package com.jqb.jsplab.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DBConnection {
	
	private Context ctx = null;
	private DataSource ds = null;
	private Connection conn = null;

	public DBConnection() throws Exception {
		ctx = new InitialContext();
		ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ds_mysql");
		conn = ds.getConnection();
	}

	public Connection getConnection()  {
		return this.conn;
	}

	public void close() throws Exception {
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				throw e;
			}
		}
	}
}
